package com.senjoeson.teamfriends.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.senjoeson.teamfriends.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyTestAdapter extends RecyclerView.Adapter {
    private int index;


    public MyTestAdapter(int index) {
        this.index = index;

    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return getViewHolder(parent);
    }

    /**
     * 获取多种viewholder
     *
     * @param parent
     * @return
     */
    public RecyclerView.ViewHolder getViewHolder(@NonNull ViewGroup parent) {
        View view = null;
        if (index == 1) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.teamfriend_item, parent, false);
            return new FirstViewHolder(view);
        } else if (index == 2) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.teamfriend_item, parent, false);
            return new FirstViewHolder(view);
        } else {

            return new SecondViewHolder(view);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return 10;
    }

    class SecondViewHolder   extends RecyclerView.ViewHolder {
        @BindView(R.id.portrait)
        ImageView mPortrait;
        @BindView(R.id.nickname)
        TextView mNickname;
        @BindView(R.id.gender)
        ImageView mGender;
        @BindView(R.id.auth)
        ImageView mAuth;
        @BindView(R.id.userinfo)
        TextView mUserinfo;
        @BindView(R.id.sign)
        TextView mSign;
        @BindView(R.id.distance)
        TextView mDistance;
        @BindView(R.id.addfocus)
        TextView mAddfocus;

        SecondViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    class  FirstViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.nickname)
        TextView mNickname;
        @BindView(R.id.publishdate)
        TextView mPublishdate;
        @BindView(R.id.content)
        TextView mContent;
        @BindView(R.id.location)
        TextView mLocation;
        @BindView(R.id.turnto)
        ImageView mTurnto;
        @BindView(R.id.message)
        ImageView mMessage;
        @BindView(R.id.love)
        ImageView mLove;

        FirstViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
